import 'package:flutter/material.dart';
import 'package:wechat/common/touch_callback.dart';

class SearchPage extends StatefulWidget {
  const SearchPage({super.key});

  @override
  State<SearchPage> createState() => _SearchPageState();
}

class _SearchPageState extends State<SearchPage> {
  FocusNode focusNode = FocusNode();

  _requestFocus() {
    FocusScope.of(context).requestFocus(focusNode);
  }

  Widget _getText(String text) {
    return TouchCallback(
      onPress: () {
        print(text);
      },
      isFeed: false,
      child: Text(
        text,
        style: const TextStyle(
          fontSize: 16,
          color: Colors.green,
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        margin: const EdgeInsets.only(top: 25),
        child: Column(
          children: [
            Stack(
              children: [
                TouchCallback(
                    onPress: () {
                      Navigator.pop(context);
                    },
                    child: Container(
                      height: 45,
                      margin: const EdgeInsets.only(left: 12, right: 10),
                      child: const Icon(
                        Icons.chevron_left,
                        color: Colors.black,
                      ),
                    )),
                Container(
                  alignment: Alignment.centerLeft,
                  height: 45,
                  margin: const EdgeInsets.only(left: 50, right: 10),
                  decoration: const BoxDecoration(
                    border: Border(
                      bottom: BorderSide(width: 1, color: Colors.green),
                    ),
                  ),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Expanded(
                        child: TextField(
                          focusNode: _requestFocus(),
                          style: const TextStyle(
                            color: Colors.black,
                            fontSize: 16,
                          ),
                          onChanged: (String value) {
                            print(value);
                          },
                          decoration: const InputDecoration(
                              hintText: "搜索", border: InputBorder.none),
                        ),
                      ),
                      Container(
                        margin: const EdgeInsets.only(right: 10),
                        child: const Icon(
                          Icons.mic,
                          color: Color(0xFFaaaaaa),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
            Container(
              margin: const EdgeInsets.only(top: 50),
              child: const Text(
                "搜索指定文章",
                style: TextStyle(
                  fontSize: 16,
                  color: Color(0xFFb5b5b5),
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(30),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  _getText("朋友圈"),
                  _getText("文章"),
                  _getText("公众号"),
                ],
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(left: 30, right: 30),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  _getText("小程序"),
                  _getText("音乐"),
                  _getText("表情"),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
